/**
 * create ns if not already done
  */
var net = net || {};
net.andersand = net.andersand || {};
net.andersand.arcomage = net.andersand.arcomage || {};

/**
 *
 * <b>Rules for cards</b> are defined here as a hash. Keys are partial image filenames. Values are two rules, one for each card on the image
 * (since an image happens to have two cards on it). Every card has one rule.
 *
 * <b>Rule format</b>
 * - type:  bricks/gems/recruits
 * - name: name of card
 * - cost: price in units as specified by type
 * - effect or effects: if only one subject is affected by the card, specify a single effect. Otherwise specify an array of effects
 *
 * <b>Effect format</b>
 * Effects have a field "subject" (who the effect will be applied to): player/enemy/all. subject can also be conditional, but a subject must always be specified.
 *
 * The following fields can vary depending on what the card does:
 * - bricks: changes the subject's amount of bricks
 * - gems: changes the subject's amount of gems
 * - recruits: changes the subject's amount of recruits
 * - quarry: changes the subject's production of bricks
 * - magic: changes the subject's production of gems
 * - dungeon: changes the subject's production of recruits
 * - special or specials: specified when something other than value changing is to occur
 *
 * When the effect varies, specify a <b>conditionalEffect</b>. Format:
 * - subject: like regular effects
 * - operand1, operator, operand2: forms the conditional expression
 * - effectTrue: what will happen when the test is true. contains anything that a regular effect does, except that subject is specified already, so don't specify that again here.
 * - effectFalse: what will happen when the test is false. contains anything that a regular effect does, except that subject is specified already, so don't specify that again here.
 *
 * When the value of an effect varies depending on subject, specify a <b>conditionalValue</b>. Format:
 * - conditionObject: any field like bricks etc.
 * - conditionCriteria: the requirement for selecting the subject with the required criteria... highest, lowest, or anything. This field will result in a call to a method by the specified name
 *
 * Note that numbers are always relative, so that setting bricks: 1 means add 1 to bricks, not to set bricks to 1.
 *
 * @author anders@andersand.net
 * @created 2011-01-30
 */
net.andersand.arcomage.rulebase = {
    "ArcoRed01" : [
        {type : "bricks", name : "Brick Shortage", cost : 0, effect : { subject : "all", bricks : -8}},
        {type : "bricks", name : "Lucky Cache", cost: 0, effect : { subject : "player", bricks : 2, gems : 2, special : "playAgain"}}
    ],
    "ArcoRed02" : [
        {type : "bricks", name : "Harmonic Ore", cost : 11, effect : { subject : "player", wall : 6, tower : 3}},
        {type : "bricks", name : "Mondo Wall", cost: 13, effect : { subject : "player", wall : 12}}
    ],
    "ArcoRed03" : [
        {type : "bricks", name : "Mother Lode", cost : 4, conditionalEffect : { subject : "player", operand1 : "player.quarry", operator : "<", operand2 : "enemy.quarry", effectTrue : {quarry : 2}, effectFalse : {quarry : 1} }},
        {type : "bricks", name : "Dwarven Miners", cost: 7, effect : { subject : "player", wall : 4, quarry: 1}}
    ],
    "ArcoRed04" : [
        {type : "bricks", name : "Focused Designs", cost : 15, effect : { subject : "player", wall : 8, tower : 5}},
        {type : "bricks", name : "Copping the Tech", cost : 5, conditionalEffect : { subject : "player", operand1 : "player.quarry", operator : "<", operand2 : "enemy.quarry", effectTrue : {quarry : "enemy.quarry"}}}
    ],
    "ArcoRed05" : [
        {type : "bricks", name : "Great Wall", cost : 16, effect : { subject : "player", wall : 15}},
        {type : "bricks", name : "Sturdy Wall", cost : 3, effect : { subject : "player", wall : 4}}
    ],
    "ArcoRed06" : [
        {type : "bricks", name : "Innovations", cost : 2, effects : [
            { subject : "all", quarry : 1},
            { subject : "player", gems : 4}
        ]},
        {type : "bricks", name : "Rock Launcher", cost : 18, effects : [
            { subject : "player", wall : 6},
            { subject : "enemy", damage : 10}
        ]}
    ],
    "ArcoRed07" : [
        {type : "bricks", name : "Tremors", cost : 7, effects : [
            { subject : "all", wall : -5},
            { subject : "player", special : "playAgain"}
        ]},
        {type : "bricks", name : "Secret Room", cost : 8, effect : { subject : "player", magic : 1, special: "playAgain"}}
    ],
    "ArcoRed08" : [
        {type : "bricks", name : "Earthquake", cost : 0, effect : { subject : "all", quarry : -1}},
        {type : "bricks", name : "Dragons Heart", cost : 24, effect : { subject : "player", wall : 20, tower: 8}}
    ],
    "ArcoRed09" : [
        {type : "bricks", name : "Collapse", cost : 4, effect: {subject : "enemy", quarry : -1}},
        {type : "bricks", name : "New equipment", cost : 6, effect : { subject : "player", quarry : 2}}
    ],
    "ArcoRed10" : [
        {type : "bricks", name : "Strip Mine", cost : 0, effect : { subject : "player", quarry : -1, wall : 10, gems: 5}},
        {type : "bricks", name : "Forced Labor", cost : 7, effect : { subject : "player", wall : 9, recruits: -5}}
    ],
    "ArcoRed11" : [
        {type : "bricks", name : "Porticulus", cost : 9, effect : { subject : "player", wall : 5, dungeon : 1}},
        {type : "bricks", name : "Crystal Rocks", cost : 9, effect : { subject : "player", wall : 7, gems: 7}}
    ],
    "ArcoRed12" : [
        {type : "bricks", name : "Rock Garden", cost : 1, effect : { subject : "player", wall : 1, tower : 1, recruits : 2}},
        {type : "bricks", name : "Flood Water", cost : 6, effect : { conditionalSubject: {conditionObject : "wall", conditionCriteria : "lowest"}, dungeon : -1, tower : -2}}
    ],
    "ArcoRed13" : [
        {type : "bricks", name : "Barracks", cost : 10, effect : { subject : "player", wall : 6, recruits : 6}, conditionalEffect : {subject : "player", operand1 : "player.dungeon", operator : "<", operand2 : "enemy.dungeon", effectTrue : {dungeon : 1}}},
        {type : "bricks", name : "Battlements", cost : 14, effects : [
            { subject : "player", wall : 7},
            { subject : "enemy", damage : 6}
        ]}
    ],
    "ArcoRed14" : [
        {type : "bricks", name : "Shift", cost : 17, effects : [
            { subject : "player", wall : "enemy.wall"},
            { subject : "enemy", wall : "player.wall"}
        ]},
        {type : "bricks", name : "void (image for bricks)"}
    ],
    "ArcoRed15" : [
        {type : "bricks", name : "Reinforced Wall", cost : 8, quantity : 2, effect : { subject : "player", wall : 8}},
        {type : "bricks", name : "void"}
    ],
    "ArcoRed16" : [
        {type : "bricks", name : "Friendly Terrain", cost : 1, quantity : 2, effect : { subject : "player", wall : 1, special : "playAgain"}},
        {type : "bricks", name : "Miners", cost : 3, quantity : 2, effect : { subject : "player", quarry : 1}}
    ],
    "ArcoRed17" : [
        {type : "bricks", name : "Work Overtime", cost : 2, quantity : 2, effect : { subject : "player", wall : 5, gems: -6}},
        {type : "bricks", name : "Basic Wall", cost : 2, quantity : 2, effect : { subject : "player", wall : 3}}
    ],
    "ArcoRed18" : [
        {type : "bricks", name : "Foundations", cost : 3, quantity : 2, conditionalEffect : { subject : "player", operand1 : "player.wall", operator : "==", operand2 : 0, effectTrue : {wall : 6}, effectFalse : {wall : 3}}},
        {type : "bricks", name : "Big Wall", cost : 5, quantity : 2, effect : { subject : "player", wall : 6}}
    ],
    "ArcoBlue01" : [
        {type : "gems", name : "Crystal Shield", cost : 12, effect : { subject : "player", tower : 8, wall : 3}},
        {type : "gems", name : "Smoky Quartz", cost : 2, effects : [
            { subject : "player", special : "playAgain"},
            { subject : "enemy", damage : 1}
        ]}
    ],
    "ArcoBlue02" : [
        {type : "gems", name : "Diamond", cost : 16, effect : { subject : "player", tower : 15}},
        {type : "gems", name : "Sanctuary", cost : 15, effect : { subject : "player", tower : 10, wall : 5, recruits : 5}}
    ],
    "ArcoBlue03" : [
        {type : "gems", name : "Prism", cost : 2, effect : { subject : "player", specials : ["drawCard","discardCard","playAgain"]}},
        {type : "gems", name : "Lodestone", cost : 5, effect : { subject : "player", tower : 3}, discardable : false}
    ],
    "ArcoBlue04" : [
        {type : "gems", name : "Solar Flare", cost : 4, effects : [
            { subject : "player", tower : 2},
            { subject : "enemy", tower : -2}
        ]},
        {type : "gems", name : "Crystal Matrix", cost : 6, effects : [
            { subject : "player", magic : 1, tower : 3},
            { subject : "enemy", tower : 1}
        ]}
    ],
    "ArcoBlue05" : [
        {type : "gems", name : "Crystallize", cost : 8, effect : { subject : "player", tower : 11, wall : -6}},
        {type : "gems", name : "Empathy Gem", cost : 14, effect : { subject : "player", tower : 8, dungeon : 1}}
    ],
    "ArcoBlue06" : [
        {type : "gems", name : "Gem Spear", cost : 4, effect : { subject : "enemy", tower : -5}},
        {type : "gems", name : "Power Burn", cost : 3, effect : { subject : "player", tower : -5, magic : 2}}
    ],
    "ArcoBlue07" : [
        {type : "gems", name : "Harmonic Vibe", cost : 7, effect : { subject : "player", tower : 3, magic : 1, wall : 3}},
        {type : "gems", name : "Parity", cost : 7, effect : { subject : "all", conditionalValue : {conditionObject : "magic", conditionCriteria : "highest"}}}
    ],
    "ArcoBlue08" : [
        {type : "gems", name : "Lava Jewel", cost : 17, effects : [
            { subject : "player", tower : 12},
            { subject : "enemy", damage : 6}
        ]},
        {type : "gems", name : "Pearl of Wisdom", cost : 9, effect : { subject : "player", tower : 5, magic : 1}}
    ],
    "ArcoBlue09" : [
        {type : "gems", name : "Shatterer", cost : 8, effects : [
            { subject : "player", magic : -1},
            { subject : "enemy", tower : -9}
        ]},
        {type : "gems", name : "Crumblestone", cost : 7, effects : [
            { subject : "player", tower : 5},
            {subject : "enemy", bricks : -6}
        ]}
    ],
    "ArcoBlue10" : [
        {type : "gems", name : "Dragon's Eye", cost : 21, effect : { subject : "player", tower: 20}},
        {type : "gems", name : "Discord", cost : 5, effect : { subject : "all", tower : -7, magic: -1}}
    ],
    "ArcoBlue11" : [
        {type : "gems", name : "Fire Ruby", cost : 13, effects : [
            { subject : "player", tower: 6},
            { subject : "enemy", tower: -4}
        ]},
        {type : "gems", name : "Quarry's Help", cost : 4, effect : { subject : "player", tower : 7, bricks: -10}}
    ],
    "ArcoBlue12" : [
        {type : "gems", name : "Bag of Baubles", cost : 0, conditionalEffect : { subject : "player", operand1 : "player.tower", operator : "<", operand2 : "enemy.tower", effectTrue : {tower : 2}, effectFalse : {tower: 1}}},
        {type : "gems", name : "Rainbow", cost : 0, effects : [
            { subject : "all", tower : 1},
            {subject : "player", gems : 3}
        ]}
    ],
    "ArcoBlue13" : [
        {type : "gems", name : "Apprentice", cost : 5, effects : [
            { subject : "player", tower : 4, recruits : -3},
            {subject : "enemy", tower : -2}
        ]},
        {type : "gems", name : "Lightning Shard", cost : 11, conditionalEffect : { subject : "enemy", operand1 : "player.tower", operator : ">", operand2 : "enemy.wall", effectTrue : {tower : -8}, effectFalse : {damage : 8}}}
    ],
    "ArcoBlue14" : [
        {type : "gems", name : "Phase Jewel", cost : 18, effect : { subject : "player", tower : 13, recruits : 6, bricks : 6}},
        {type : "gems", name : "void (image for gems)"}
    ],
    "ArcoBlue15" : [
        {type : "gems", name : "Gemstone Flaw", cost : 2, quantity : 2, effect : {subject : "enemy", tower : -3}},
        {type : "gems", name : "void"}
    ],
    "ArcoBlue16" : [
        {type : "gems", name : "Quartz", cost : 1, quantity : 2, effect : {subject : "player", tower : 1, special : "playAgain"}},
        {type : "gems", name : "Ruby", cost : 3, quantity : 2, effect : {subject : "player", tower: 5}}
    ],
    "ArcoBlue17" : [
        {type : "gems", name : "Amethyst", cost : 2, quantity : 2, effect : {subject : "player", tower: 3}},
        {type : "gems", name : "Spell Weavers", cost: 3, quantity : 2, effect : {subject : "player", magic: 1}}
    ],
    "ArcoBlue18" : [
        {type : "gems", name : "Emerald", cost : 6, quantity : 2, effect : {subject : "player", tower: 8}},
        {type : "gems", name : "Sapphire", cost : 10, quantity : 2, effect : {subject : "player", tower: 11}}
    ],
    "ArcoGreen01" : [
        {type : "recruits", name : "Mad Cow Disease", cost : 0, effect : {subject : "all", recruits: -6}},
        {type : "recruits", name : "Elven Archers", cost : 10, conditionalEffect : { subject : "enemy", operand1 : "player.wall", operator : ">", operand2: "enemy.wall", effectTrue : {tower: -6}, effectFalse: {damage : 6}}}
    ],
    "ArcoGreen02" : [
        {type : "recruits", name : "Succubus", cost : 14, effect : {subject : "enemy", tower : -5, recruits: -8}},
        {type : "recruits", name : "Minotaur", cost : 3, effect : {subject : "player", dungeon : 1}}
    ],
    "ArcoGreen03" : [
        {type : "recruits", name : "Elven Scout", cost : 2, effect : {subject : "player", specials : ["drawCard","discardCard","playAgain"]}},
        {type : "recruits", name : "Stone Giant", cost : 15, effects : [
            { subject : "player", wall: 4},
            {subject : "enemy", damage : 10}
        ]}
    ],
    "ArcoGreen04" : [
        {type : "recruits", name : "Goblin Archers", cost : 4, effects : [
            { subject : "player", damage : 1},
            {subject : "enemy", tower : -3}
        ]},
        {type : "recruits", name : "Shadow Faerie", cost : 6, effects : [
            { subject : "player", special : "playAgain"},
            {subject : "enemy", tower : -2}
        ]}
    ],
    "ArcoGreen05" : [
        {type : "recruits", name : "Rock Stompers", cost : 11, effect : {subject : "enemy", damage : 8, quarry: -1}},
        {type : "recruits", name : "Thief", cost : 12, effects : [
            { subject : "player", gems : 5, bricks : 3},
            {subject : "enemy", gems : -10, bricks : -5}
        ]}
    ],
    "ArcoGreen06" : [
        {type : "recruits", name : "Little Snakes", cost : 6, effect : {subject : "enemy", tower : -4}},
        {type : "recruits", name : "Vampire", cost : 17, effect : {subject : "enemy", damage : 10, recruits : -5, dungeon : -1}}
    ],
    "ArcoGreen07" : [
        {type : "recruits", name : "Tower Gremlin", cost : 8, effects : [
            { subject : "player", wall:4, tower:2},
            {subject : "enemy", damage: 2}
        ]},
        {type : "recruits", name : "Full Moon", cost : 0, effects : [
            { subject : "player", recruits: 3},
            {subject : "all", dungeon: 1}
        ]}
    ],
    "ArcoGreen08" : [
        {type : "recruits", name : "Slasher", cost : 5, effect : {subject : "enemy", damage: 6}},
        {type : "recruits", name : "Dragon", cost : 25, effect : {subject : "enemy", damage: 20, gems: -10, dungeon: -1}}
    ],
    "ArcoGreen09" : [
        {type : "recruits", name : "Rabid Sheep", cost : 6, effect : {subject : "enemy", damage: 6, recruits: -3}},
        {type : "recruits", name : "Imp", cost : 5, effects : [
            { subject : "all", recruits: -5, gems: -5, bricks: -5},
            {subject : "enemy", damage: 6}
        ]}
    ],
    "ArcoGreen10" : [
        {type : "recruits", name : "Spizzer", cost : 8, conditionalEffect : {subject : "enemy", operand1 : "enemy.wall", operator : "==", operand2 : 0, effectTrue : {damage : 10}, effectFalse:{damage:6}}},
        {type : "recruits", name : "Werewolf", cost : 9, effect : {subject : "enemy", damage: 9}}
    ],
    "ArcoGreen11" : [
        {type : "recruits", name : "Corrosion Cloud", cost : 11, conditionalEffect : {subject : "enemy", operand1 : "enemy.wall", operator : ">", operand2 : 0, effectTrue : {damage : 10}, effectFalse:{damage:7}}},
        {type : "recruits", name : "Unicorn", cost : 9, conditionalEffect : {subject : "enemy", operand1 : "player.magic", operator : ">", operand2 : "enemy.magic", effectTrue : {damage : 12}, effectFalse:{damage:8}}}
    ],
    "ArcoGreen12" : [
        {type : "recruits", name : "Spearman", cost : 2, conditionalEffect : {subject : "enemy", operand1 : "player.wall", operator : ">", operand2 : "enemy.wall", effectTrue : {damage : 3}, effectFalse:{damage:2}}},
        {type : "recruits", name : "Gnome", cost : 2, effects : [
            { subject : "player", gems: 1},
            {subject : "enemy", damage: 3}
        ]}
    ],
    "ArcoGreen13" : [
        {type : "recruits", name : "Berserker", cost : 4, effects : [
            { subject : "player", tower:-3},
            {subject : "enemy", damage: 8}
        ]},
        {type : "recruits", name : "Warlord", cost : 13, effects : [
            { subject : "player", gems: -3},
            {subject : "enemy", damage: 13}
        ]}
    ],
    "ArcoGreen14" : [
        {type : "recruits", name : "Pegasus Lancer", cost : 18, effect : {subject : "enemy", tower: -12}},
        {type : "recruits", name : "void (image for recruits)"}
    ],
    "ArcoGreen15" : [
        {type : "recruits", name : "Ogre", cost : 6, quantity : 2, effect : {subject: "enemy", damage: 7}},
        {type : "recruits", name : "void"}
    ],
    "ArcoGreen16" : [
        {type : "recruits", name : "Faerie", cost : 1, quantity : 2, effects : [
            { subject : "player", special : "playAgain"},
            {subject : "enemy", damage: 2}
        ]},
        {type : "recruits", name : "Moody Goblins", cost : 1, quantity : 2, effects : [
            { subject : "player", gems: -3},
            {subject : "enemy", damage: 4}
        ]}
    ],
    "ArcoGreen17" : [
        {type : "recruits", name : "Orc", cost : 3, quantity : 2, effect : {subject: "enemy", damage: 5}},
        {type : "recruits", name : "Dwarves", cost : 5, quantity : 2, effects : [
            { subject : "player", wall: 3},
            {subject : "enemy", damage: 4}
        ]}
    ],
    "ArcoGreen18" : [
        {type : "recruits", name : "Goblin Mob", cost : 3, quantity : 2, effects : [
            { subject : "player", damage: 3},
            {subject : "enemy", damage: 6}
        ]},
        {type : "recruits", name : "Troll Trainer", cost : 7, quantity : 2, effect : {subject: "player", dungeon : 2}}
    ]
};
